package com.mmd.parkingspringboot.service;

import com.mmd.parkingspringboot.mapper.ProjectMapper;
import com.mmd.parkingspringboot.model.Project;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProjectService {
    @Autowired
    private ProjectMapper projectMapper;
    @Autowired
    JavaMailSender javaMailSender;

    public Project projectLogin(String phone, String password) {
        Project i = projectMapper.projectLogin(phone,password);
        return i;
    }

    public int projectInsert(Project project) {
        int i = projectMapper.insert(project);
        return i;
    }

    public int projectUpdate(Project project) {
        int i = projectMapper.updateByPrimaryKeySelective(project);
        return i;
    }

    public List<Project> all() {
        return projectMapper.all();
    }

    public int delete(Integer projectId) {
        int i = projectMapper.deleteByPrimaryKey(projectId);
        return i;
    }

    public Project projectFind(String email) {
        Project project=projectMapper.projectFind(email);
        return project;
    }

    public void sendSimpleMail(String from, String to, String cc, String subject, String content) {
        SimpleMailMessage simpMsg = new SimpleMailMessage();
        simpMsg.setFrom(from);
        simpMsg.setTo(to);
        simpMsg.setCc(cc);
        simpMsg.setSubject(subject);
        simpMsg.setText(content);
        javaMailSender.send(simpMsg);
    }
}
